#include "Coinbox.h"
// methodes


void Coinbox::Stop()
{
  
}

void Coinbox::waitForAmount(int amount){
  moneyinserted = 0;
  halOutput->set_coin_leds(moneyinserted);
  halInput->clearChange();
  Serial.print("Please insert: ");
  Serial.println(amount);
  while(moneyinserted<amount){
    int tmp = checkForMoney();
    if(tmp<0){
      moneyinserted = 0;
    }else{
      moneyinserted += tmp;
    }
    halOutput->set_coin_leds(moneyinserted);
  }
  Serial.println("OK");
}

int Coinbox::checkForMoney(void)
{
  halInput->update();
  if(halInput->change){
    if(halInput->readTen()){
      Serial.println("Inserted 10");
      return 10;
    }
    if(halInput->readFifty()){
      Serial.println("Inserted 50");
      return 50;
    }
    if(halInput->readTwoHundred()){
      Serial.println("Inserted 200");
      return 200;
    }
    if(halInput->readClear()){
      return -1;
    }
    halInput->clearChange();
  }
  return 0;
}

